package com.vm.action.system;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Preparable;
import com.vm.action.ActionSuper;
import com.vm.common.Page;
import com.vm.dao.system.IMessageTypeDao;
import com.vm.entity.MessageType;
import com.vm.log4j.CustomizeLog4j;

public class MessageTypeAction extends ActionSuper implements Preparable {
	private static Logger log = CustomizeLog4j.getLogger(MessageTypeAction.class);
	
	private MessageType messageType;
	private IMessageTypeDao messageTypeDao;
	private Page<MessageType> page;
	private String pageLinkList;
	
	public void prepare() throws Exception {
	}

	
	public String list() {
		page = this.messageTypeDao.page(PAGE_ROW_SIZE, super.getPageNumber());
		this.pageLinkList =super.getSplitPageLink("/MessageTypeAction_list.do?", page);
		return SUCCESS;
	}

	public String add() throws Exception {
		return SUCCESS;
	}

	public String save() throws Exception {
		String[] msgArg = new String[] { "messageTypeAction_list.do"};
		String msg = null;
		try {
			messageTypeDao.save(messageType);
			msg = super.getResourceMessage("insert_messageType_success", msgArg);
		} catch (Exception e) {
			log.error("UpdateCircleAction save messageType error  ", e);
			msg = super.getResourceMessage("insert_messageType_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;
	}

	public String edit(){
		messageType = messageTypeDao.findById(this.messageType.getPxId());
		return SUCCESS;
	}

	public String update() throws Exception {
		String[] msgArg = new String[] { "messageTypeAction_list.do"};
		String msg = null;
		try {
			messageTypeDao.update(messageType);
			msg = super.getResourceMessage("update_messageType_success", msgArg);
		} catch (Exception e) {
			log.error("UpdateCircleAction update messageType error  ", e);
			msg = super.getResourceMessage("update_messageType_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;

	}

	public String delete() {
		String[] msgArg = new String[] { "messageTypeAction_list.do"};
		String msg = null;
		try {
			messageTypeDao.deleteById(this.messageType.getPxId());
			msg = super.getResourceMessage("delete_messageType_success", msgArg);
		} catch (Exception e) {
			log.error("UpdateCircleAction delete messageType error  ", e);
			msg = super.getResourceMessage("delete_messageType_err", msgArg);
		}
		super.setShowMessage(msg);
		return super.SHOW_MESSAGE_RESULT;
	}


	public MessageType getMessageType() {
		return messageType;
	}


	public void setMessageType(MessageType messageType) {
		this.messageType = messageType;
	}


	public IMessageTypeDao getMessageTypeDao() {
		return messageTypeDao;
	}


	public void setMessageTypeDao(IMessageTypeDao messageTypeDao) {
		this.messageTypeDao = messageTypeDao;
	}


	public Page<MessageType> getPage() {
		return page;
	}


	public void setPage(Page<MessageType> page) {
		this.page = page;
	}


	public String getPageLinkList() {
		return pageLinkList;
	}


	public void setPageLinkList(String pageLinkList) {
		this.pageLinkList = pageLinkList;
	}
	
}
